/*
 * @Author: cl
 * @Description:
 * @Date: 2023-05-18 17:10:54
 * @LastEditTime: 2023-06-06 17:15:39
 * @FilePath: \vue3scaffold\src\utils\helper.ts
 * @LastEditors: cl
 */
import _ from "lodash";
class Helper {
  public env = {} as ImportMetaEnv;
  constructor() {
    this.env = this.parseEnv();
  }

  private parseEnv(): ImportMetaEnv {
    const envs: any = _.cloneDeep(import.meta.env);
    Object.entries(import.meta.env as Record<string, any>).forEach(
      ([key, value]) => {
        if (value === "true" || "false") {
          envs[key] = value === "true" ? true : false;
        } else if (/^\d+$/.test(value)) {
          envs[key] = Number(value);
        } else if (value == "null") {
          envs[key] = null;
        } else if (value == "undefined") {
          envs[key] = "undefined";
        } else {
          envs[key] = value;
        }
      }
    );

    return envs;
  }
}
const helper = new Helper();
const env = helper.env;
export default helper;
export {env}
